
import { createI18n, useI18n } from 'vue-i18n'
import store from "@/sheep/store"
// const files = import.meta.globEager('./*.js');
const files = import.meta.glob('./*.json', { eager: true });
const messages = {};
Object.keys(files).forEach((key) => {
	messages[key.replace(/(.*\/)*([^.]+).*/gi, '$2')] = files[key].default;
});
// console.log(messages);

export let i18n = {}
export const initI18n = (app) => {
	console.log(store('app').language,uni.getStorageSync('language'));
	uni.setLocale(store('app').language || uni.getLocale())
	i18n = createI18n({
		locale: store('app').language || uni.getLocale(), // 默认语言
		fallbackLocale: 'en', // 回退语言
		messages, // 多语言内容
	})
	app.use(i18n);
};

export function getAllLanguage() {
	return messages
}


// 未翻译的key
// import a from './en.json'
// import b from './id.json'

// const missingKeys = [];
// const keys1 = Object.keys(a);
// const keys2 = Object.keys(b);

// for (const key of keys1) {
// 	if (!keys2.includes(key)) {
// 		missingKeys.push(key);
// 	}
// }

// console.log(missingKeys, '未翻译的key');
